package net.onceface.application.assembler;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import net.onceface.application.dto.ProductDTO;
import net.onceface.core.domain.Product;

public class ProductAssembler {

	public static ProductDTO toDTO(Product product){
		if(product == null){
			return null;
		}
		ProductDTO result = new ProductDTO();
		result.setAbolishDate(product.getAbolishDate());
		result.setCatgoryId(product.getCatgoryId());
		result.setCollection(product.getCollection());
		result.setCreateDate(product.getCreateDate());
		result.setId(product.getId());
		result.setLevel(product.getLeve());
		result.setMoonSaleVolume(product.getMoonSaleVolume());
		result.setName(product.getName());
		result.setOriginalPrice(product.getOriginalPrice());
		result.setPicture(product.getPicture());
		result.setPrice(product.getPrice());
		result.setSale(result.isSale());
		result.setSn(product.getSn());
		result.setSortOrder(product.getSortOrder());
		result.setSpecId(product.getSpecId());
		result.setSpecName(product.getSpecName());
		result.setStock(product.getStock());
		result.setTotalSaleVolume(product.getTotalSaleVolume());
		result.setVersion(product.getVersion());
		return result;
	}
	
	public static Product toEntity(ProductDTO product){
		if(product == null){
			return null;
		}
		Product result = new Product();
		result.setAbolishDate(product.getAbolishDate());
		result.setCatgoryId(product.getCatgoryId());
		result.setCollection(product.getCollection());
		result.setCreateDate(product.getCreateDate());
		result.setId(product.getId());
		result.setLeve(product.getLevel());
		result.setMoonSaleVolume(product.getMoonSaleVolume());
		result.setName(product.getName());
		result.setOriginalPrice(product.getOriginalPrice());
		result.setPicture(product.getPicture());
		result.setPrice(product.getPrice());
		result.setSale(result.isSale());
		result.setSn(product.getSn());
		result.setSortOrder(product.getSortOrder());
		result.setSpecId(product.getSpecId());
		result.setSpecName(product.getSpecName());
		result.setStock(product.getStock());
		result.setTotalSaleVolume(product.getTotalSaleVolume());
		result.setVersion(product.getVersion());
		return result;
	}
	
	public static List<Product>  toEntities(Collection<ProductDTO>  products){
		if (products == null) {
			return null;
		}
		List<Product> results = new ArrayList<Product>();
		for (ProductDTO each : products) {
			results.add(toEntity(each));
		}
		return results;
	}
	
	public static List<ProductDTO>  toDTOs(Collection<Product>  products){
		if (products == null) {
			return null;
		}
		List<ProductDTO> results = new ArrayList<ProductDTO>();
		for (Product each : products) {
			results.add(toDTO(each));
		}
		return results;
	}
}
